package com.ittest.mapper.system;

import com.ittest.domain.system.Role;
import com.ittest.domain.system.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

    @Update("update users set password = #{password} where id = #{id}")
    void updatePwdById(@Param("id") String id, @Param("password") String newPwd);


    @Select("select * from users " +
            " where username = #{username} and password = #{password}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "email",property = "email"),
            @Result(column = "password",property = "password"),
            @Result(column = "phoneNum",property = "phoneNum"),
            @Result(column = "status",property = "status")
    })
    User findByUsernameAndPwd(@Param("username") String username, @Param("password") String password);

    /*@Select("select * from users")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "email",property = "email"),
            @Result(column = "password",property = "password"),
            @Result(column = "phoneNum",property = "phoneNum"),
            @Result(column = "status",property = "status"),
            @Result(column = "statusStr",property = "statusStr")
    })*/
    List<User> findAll();

    List<User> findAll(String sname);

    @Insert("insert into users values (#{id},#{email},#{username},"+
            "#{password},#{phoneNum},#{status})")
    void save(User user);


    void delete(String[] arr);

    // 根据id查
    @Select("select * from users where id = #{id}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "email",property = "email"),
            @Result(column = "password",property = "password"),
            @Result(column = "phoneNum",property = "phoneNum"),
            @Result(column = "status",property = "status"),
            @Result(column = "statusStr",property = "statusStr")
    })
    User findById(String id);


    @Delete("delete from users_role where userId=#{userId}")
    void deleteRole(String userId);

    @Insert("insert into users_role (userId,roleId) values (#{userId},#{roleId})")
    void updateRole(@Param("userId") String userId, @Param("roleId") String roleId);

    @Update("update users set STATUS = #{status} where id = #{id}")
    void change(@Param("status") Integer status,@Param("id") String id);
}
